home *** CD-ROM | disk | FTP | other *** search
/ Champak 43 / Vol 43.iso / games / menininh.swf / scripts / __Packages / Jewel.as < prev    next >
Encoding:
Text File  |  2007-07-06  |  2.0 KB  |  93 lines

  1. class Jewel extends MovieClip
  2. {
  3.    static var MAXIMUM_FALLING_SPEED = 40;
  4.    var mType = 0;
  5.    var mIsDying = false;
  6.    var mIsDead = false;
  7.    var mOrigY = 0;
  8.    var mTargetX = 0;
  9.    var mTargetY = 0;
  10.    var mIsFalling = false;
  11.    var mIsMoving = false;
  12.    var mYSpeed = 0;
  13.    function Jewel()
  14.    {
  15.       super();
  16.    }
  17.    function setType(t)
  18.    {
  19.       this.mType = t;
  20.    }
  21.    function getType()
  22.    {
  23.       return this.mType;
  24.    }
  25.    function die()
  26.    {
  27.       if(!this.mIsDying)
  28.       {
  29.          this._parent._parent._parent.mDestroyedPieces = this._parent._parent._parent.mDestroyedPieces + 1;
  30.          this.gotoAndPlay("boom");
  31.       }
  32.       this.mIsDying = true;
  33.    }
  34.    function isDying()
  35.    {
  36.       return this.mIsDying;
  37.    }
  38.    function isDead()
  39.    {
  40.       return this.mIsDead;
  41.    }
  42.    function isFalling()
  43.    {
  44.       return this.mIsFalling;
  45.    }
  46.    function isMoving()
  47.    {
  48.       return this.mIsMoving;
  49.    }
  50.    function fall(x, y)
  51.    {
  52.       this.mOrigY = this._y;
  53.       this._y = this._y + 1;
  54.       this.mIsFalling = true;
  55.       this.mTargetX = x;
  56.       this.mTargetY = y;
  57.    }
  58.    function move(x, y)
  59.    {
  60.       this.mIsMoving = true;
  61.       this.mTargetX = x;
  62.       this.mTargetY = y;
  63.    }
  64.    function onEnterFrame()
  65.    {
  66.       if(this.mIsFalling)
  67.       {
  68.          this.mYSpeed = (this._y - this.mOrigY) * 2;
  69.          if(this.mYSpeed > Jewel.MAXIMUM_FALLING_SPEED)
  70.          {
  71.             this.mYSpeed = Jewel.MAXIMUM_FALLING_SPEED;
  72.          }
  73.          this._y += this.mYSpeed;
  74.          if(this._y > this.mTargetY)
  75.          {
  76.             this._y = this.mTargetY;
  77.             this.mIsFalling = false;
  78.          }
  79.       }
  80.       else if(this.mIsMoving)
  81.       {
  82.          this._x += (this.mTargetX - this._x) / 3;
  83.          this._y += (this.mTargetY - this._y) / 3;
  84.          if(Math.abs(this.mTargetX - this._x) < 1 && Math.abs(this.mTargetY - this._y) < 1)
  85.          {
  86.             this.mIsMoving = false;
  87.             this._x = this.mTargetX;
  88.             this._y = this.mTargetY;
  89.          }
  90.       }
  91.    }
  92. }
  93.